home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / RS232GID.ZIP / RS232GID.TXT
Text File  |  1989-10-20  |  22KB  |  412 lines

  1.  
  2.                  A Practical Guide to RS-232 Interfacing
  3.  
  4.                 by Lawrence E. Hughes. Mycroft Labs, Inc.
  5.                   P.O. Box 6045, Tallahassee, FL 32301
  6.  
  7.      The following information  is intended  to collect  together in
  8.      one place,  and explain in  relatively simple terms,  enough of
  9.      the details  of the  RS-232 standard  to allow  a technician to
  10.      construct and/or  debug  interfaces  between  any  two  "RS-232
  11.      Compatible" devices.  A more  detailed coverage  of the subject
  12.      may  be  found   in  the   book  "Technical   Aspects  of  Data
  13.      Communication" by John E. McNamara (1977, Digital Press).
  14.  
  15.      This guide is  necessary  due  to  the  casual way that vendors
  16.      implement "RS-232" interfaces, sometimes omitting required sig-
  17.      nals, requiring optional ones,  or worse,  implementing signals
  18.      incorrectly.  Due to  this,  and  a  lack  of readily available
  19.      information about the real EIA standard, there is often consid-
  20.      erable confusion involved  in  trying  to  interface two RS-232
  21.      devices.
  22.  
  23.  
  24.                                BACKGROUND
  25.  
  26.      RS-232-C is  the most  recent version  of the  EIA (Electronics
  27.      Industry Association) standard for low speed serial data commu-
  28.      nication.  It defines a number of parameters concerning voltage
  29.      levels,  loading characteristics and timing relationships.  The
  30.      actual connectors which are almost universally used (DB-25P and
  31.      DB-25S, sometimes called "EIA connectors") are recommended, but
  32.      not mandatory.  Typical practice  requires mounting  the female
  33.      (DB-25S) connector on  the chassis  of communication equipment,
  34.      and male (DB-25P)  connectors on the  cable connecting two such
  35.      devices.
  36.  
  37.      There are two main classes of RS-232 devices,  namely DTE (Data
  38.      Terminal  Equipment),   such  as   terminals,   and  DCE  (Data
  39.      Communication Equipment), such as modems.  Typically,  one only
  40.      interfaces a DTE  to a DCE,  as  opposed to one  DTE to another
  41.      DTE,  or one DCE to another DCE,  although there are ways to do
  42.      the later two by  building non-standard cables.  Rarely if ever
  43.      are more  than  two  devices  involved  in  a  given  interface
  44.      (multidrop is not supported).  A serial  port on a computer may
  45.      be implemented as either DTE or DCE,  depending on what type of
  46.      device it is intended to support.
  47.  
  48.      RS-232 is intended  for  relatively  short  (50  feet or less),
  49.      relatively low speed  (19,200 bits  per second  or less) serial
  50.      (as opposed to parallel) communications.  Both asynchronous and
  51.      synchronous serial encoding are supported. As 'digital' signals
  52.      (switched D.C.  voltage,  such  as square  waves) are used,  as
  53.      opposed to 'analog' signals (continuously varying voltage, such
  54.      as sine waves) a  very wide  bandwidth channel  (such as direct
  55.      wire) is required. A limited bandwidth channel (such as a phone
  56.      circuit) would  cause  severe  and  unacceptable distortion and
  57.      consequent loss of information.
  58.  
  59.      RS-232 will support simplex,  half-duplex,  or full-duplex type
  60.      channels. In a simplex channel,  data will only ever be travel-
  61.      ling in one direction,  e.g.  from DCE to DTE. An example might
  62.      be a 'Receive Only' printer. In a half-duplex channel, data may
  63.      travel in either  direction,  but at  any given  time data will
  64.      only be travelling  in  one  direction,  and  the  line must be
  65.      'turned around' before data can  travel in the other direction.
  66.      An example might be  a Bell 201  style modem.  In a full-duplex
  67.      channel, data may travel in both directions simultaneously.  An
  68.      example might be a Bell 103 style modem.  Certain of the RS-232
  69.      'hand-shaking' lines  are used  to resolve  problems associated
  70.      with these modes,  such  as which direction  data may travel at
  71.      any given instant.
  72.  
  73.      If one of the devices involved in an RS-232 interface is a real
  74.      modem (especially  a  half-duplex  modem),  the  'hand-shaking'
  75.      lines must be supported,  and  the timing relationships between
  76.      them are quite important. These lines are typically much easier
  77.      to deal with if no modems are involved. In certain cases, these
  78.      lines may be used to allow  one device (which is receiving data
  79.      at a higher rate than it is capable of processing indefinitely)
  80.      to cause the other device to pause while the first one 'catches
  81.      up'. This use of the hand-shaking lines was not really intended
  82.      by the designers of the RS-232 standard, but it is a useful by-
  83.      product of the way such interfaces are typically implemented.
  84.  
  85.      Much of  the  RS-232  standard  is  concerned  with  support of
  86.      'modems'.  These are devices which can convert a serial digital
  87.      data signal into  an  analog  signal  compatible  with a narrow
  88.      bandwidth (e.g.  3  kHz) channel  such as  a switched telephone
  89.      circuit,  and back into serial  digital data on  the other end.
  90.      The first process is  called 'MOdulation',  and the second pro-
  91.      cess is called  'DEModulation',  hence  the  term 'MODEM'.  The
  92.      actual process used  (at  data  rates  of  up  to 1200 bits per
  93.      second) is FSK  (Frequency Shift Keying),  in  which a constant
  94.      frequency sine wave  (called  the  'carrier')  is  shifted to a
  95.      slightly higher or  slightly  lower  frequency  to  represent a
  96.      logic 0 or logic 1,  respectively.  In a half duplex modem, the
  97.      entire available bandwidth is used for one direction. In a full
  98.      duplex modem,  the available bandwidth is divided into two sub-
  99.      bands,  hence there is  both an  'originate carrier' (e.g.  for
  100.      data from the terminal  to the computer),  and  an 'answer car-
  101.      rier' (e.g.  for data from  the computer to the terminal).  The
  102.      actual frequencies (in Hertz) used on the Bell 103A full duplex
  103.      modem are:
  104.  
  105.           signal    state  Originate  Answer
  106.  
  107.           logic 0   SPACE    1180      1850
  108.           carrier            1080      1750
  109.           logic 1   MARK      980      1650
  110.  
  111.  
  112.                THE STANDARD CIRCUITS AND THEIR DEFINITIONS
  113.  
  114.      For the purposes of the RS-232 standard, a 'circuit' is defined
  115.      to be a continuous wire from one device to the other. There are
  116.      25 circuits in the full specification,  less than half of which
  117.      are at all likely to be found in a given interface. In the sim-
  118.      plest case,  a full-duplex interface may be implemented with as
  119.      few as 3 circuits. There is a certain amount of confusion asso-
  120.      ciated with the names of  these circuits,  partly because there
  121.      are three different naming  conventions (common name,  EIA cir-
  122.      cuit name,  and CCITT circuit name).  The table below lists all
  123.      three names,  along with the circuit  number (which is also the
  124.      connector pin with which that circuit is normally associated on
  125.      both ends).  Note that the signal  names are from the viewpoint
  126.      of the DTE (e.g.  Transmit Data is  data being sent by the DTE,
  127.      but received by the DCE).
  128.  
  129.           PIN NAME EIA CCITT DTE-DCE FUNCTION
  130.  
  131.            1  CG    AA  101    ---   Chassis Ground
  132.            2  TD    BA  103    -->   Transmit Data
  133.            3  RD    BB  104    <--   Receive Data
  134.            4  RTS   CA  105    -->   Request To Send
  135.            5  CTS   CB  106    <--   Clear To Send
  136.            6  DSR   CC  107    <--   Data Set Ready
  137.            7  SG    AB  102    ---   Signal Ground
  138.            8  DCD   CF  109    <--   Data Carrier Detect
  139.            9*                  <--   Pos. Test Voltage
  140.           10*                  <--   Neg. Test Voltage
  141.           11                         (usually not used)
  142.           12+ SCDC  SCF 122    <--   Sec. Data Car. Detect
  143.           13+ SCTS  SCB 121    <--   Sec. Clear To Send
  144.           14+ STD   SBA 118    -->   Sec. Transmit Data
  145.           15# TC    DB  114    <--   Transmit Clock
  146.           16+ SRD   SBB 119    <--   Sec. Receive Data
  147.           17#  RC   DD  115    <--   Receive Clock
  148.           18                         (not usally used)
  149.           19+ SRTS  SCA 120    -->   Sec. Request To Send
  150.           20  DTR   CD  108.2  -->   Data Terminal Ready
  151.           21* SQ    CG  110    <--   Signal Quality
  152.           22  RI    CE  125    <--   Ring Indicator
  153.           23*       CH  111    -->   Data Rate Selector
  154.                     CI  112    <--   Data Rate Selector
  155.           24* XTC   DA  113    -->   Ext. Transmit Clock
  156.           25*                  -->   Busy
  157.  
  158.      In the above, the character following the pin number means:
  159.  
  160.           *   rarely used
  161.           +   used only if secondary channel implemented
  162.           #   used only on synchronous interfaces
  163.  
  164.      Also,   arrow  direction  indicates  which  end  (DTE  or  DCE)
  165.      originates each signal,  except for the ground lines (---). For
  166.      example, circuit 2 (TD) is originated by the DTE,  and received
  167.      by the DCE. Certain of the above circuits (11,  14, 16, and 18)
  168.      are used only, or in a different way, by Bell 208A modems.
  169.  
  170.      A secondary channel is sometimes used to provide a very slow (5
  171.      to 10 bits per second) path for return information (such as ACK
  172.      or NAK characters) on a  primarily half duplex channel.  If the
  173.      modem used suppports  this  feature,  it  is  possible  for the
  174.      receiver to accept or reject  a message without having to 'turn
  175.      the line around',  a  process  that  usally  takes  100  to 200
  176.      milliseconds.
  177.  
  178.      On the above  circuits,  all voltages  are with  respect to the
  179.      Signal Ground (SG) line. The following conventions are used:
  180.  
  181.           Voltage        Signal    Logic     Control
  182.           +3 to +25      SPACE       0          On
  183.           -3 to -25      MARK        1          Off
  184.  
  185.      Note that the voltage values are inverted from the logic values
  186.      (e.g.  the more  positive logic  value corresponds  to the more
  187.      negative voltage).  Note also that a logic 0 corresponds to the
  188.      signal name being 'true' (e.g.  if the  DTR line is at logic 0,
  189.      that is, in the +3 to +25 voltage range, then the Data Terminal
  190.      IS Ready).
  191.  
  192.  
  193.                ELECTRICAL CHARACTERISTICS OF EACH CIRCUIT
  194.  
  195.      The following criteria apply  to the electrical characteristics
  196.      of each of the above lines:
  197.  
  198.      1) The magnitude of  an open  circuit voltage  shall not exceed
  199.         25V.
  200.  
  201.      2) The driver  shall be  able to  sustain a  short to any other
  202.         wire in the cable  without damage to itself  or to the other
  203.         equipment,  and the short  circuit current  shall not exceed
  204.         0.5 ampere.
  205.  
  206.      3) Signals shall be considered in the MARK (logic 1) state when
  207.         the voltage is more  negative than  -3V with  respect to the
  208.         Signal Ground.  Signals  shall  be  considered  in the SPACE
  209.         (logic 0) state when  the voltage  is more  positive that 3V
  210.         with respect to the Signal Ground. The range between -3V and
  211.         3V is  defined as  the transition  region,  within which the
  212.         signal state is not defined.
  213.  
  214.      4) The load impedance  shall have a DC  resistance of less than
  215.         7000 ohms when measured  with an applied  voltage of from 3V
  216.         to 25V but more than 3000  ohms when measured with a voltage
  217.         of less than 25V.
  218.  
  219.      5) When the  terminator load resistance  meets the requirements
  220.         of Rule 4 above,  and the terminator open circuit voltage is
  221.         0V,  the magnitude of  the  potential  of  that circuit with
  222.         respect to Signal Ground will be in the 5V to 15V range.
  223.  
  224.      6) The driver  shall  assert  a  voltage  between  -5V and -15V
  225.         relative to  the signal  ground to  represent a  MARK signal
  226.         condition.  The driver shall assert a voltage between 5V and
  227.         15V relative to the Signal Ground  to represent a SPACE sig-
  228.         nal condition.  Note that this rule in conjunction with Rule
  229.         3 above allows  for 2V  of noise  margin.  Note also that in
  230.         practice, -12V and 12V are typically used.
  231.  
  232.      7) The driver  shall change  the output  voltage at  a rate not
  233.         exceeding 30 volts  per microsecond,  but  the time required
  234.         for the signal  to pass  through the  -3V to  +3V transition
  235.         region shall not exceed 1 millisecond, or 4 percent of a bit
  236.         time, whichever is smaller.
  237.  
  238.      8) Lower capacitance cable allows longer runs.
  239.  
  240.      9) The impedance  of the driver  circuit under power-off condi-
  241.         tions shall be greater than 300 ohms.
  242.  
  243.      Note that two  widely available integrated  circuit chips (1488
  244.      and 1489)  implement TTL  to RS232  drivers (4  per chip),  and
  245.      RS232 receivers to TTL (also 4  per chip),  in a manner consis-
  246.      tent with all of the above rules.
  247.  
  248.  
  249.                  DEFINITION OF THE MOST COMMON CIRCUITS
  250.  
  251.      1 CG Chassis Ground
  252.  
  253.      This circuit  (also  called  Frame  Ground)  is  a mechanism to
  254.      insure that  the chassis  of the  two devices  are at  the same
  255.      potential,  to prevent electrical shock  to the operator.  Note
  256.      that this circuit is  not used as the  reference for any of the
  257.      other voltages. This circuit is optional.  If it is used,  care
  258.      should be taken to not set up ground loops.
  259.  
  260.      2 TD Transmit Data
  261.  
  262.      This circuit is the  path whereby serial data  is sent from the
  263.      DTE to the  DCE.  This circuit  must be  present if  data is to
  264.      travel in that direction at any time.
  265.  
  266.      3 RD Receive Data
  267.  
  268.      This circuit is the  path whereby serial data  is sent from the
  269.      DCE to the  DTE.  This circuit  must be  present if  data is to
  270.      travel in that direction at any time.
  271.  
  272.      4 RTS Request To Send
  273.  
  274.      This circuit is the  signal that indicates  that the DTE wishes
  275.      to send data  to the DCE  (note that no  such line is available
  276.      for the opposite direction,  hence the DTE must always be ready
  277.      to accept data). In normal operation,  the RTS line will be OFF
  278.      (logic 1 / MARK). Once the DTE has data to send, and has deter-
  279.      mined that  the channel  is not  busy,  it will  set RTS  to ON
  280.      (logic 0 / SPACE),  and  await an ON condition  on CTS from the
  281.      DCE,  at which time it may then begin sending.  Once the DTE is
  282.      through sending,  it will reset RTS to OFF (logic 1 / MARK). On
  283.      a full-duplex or simplex channel,  this signal may be set to ON
  284.      once at initialization and left  in that state.  Note that some
  285.      DCEs must have an  incoming RTS in  order to transmit (although
  286.      this is not strictly according to the standard).  In this case,
  287.      this signal must either be brought across from the DTE, or pro-
  288.      vided by a wraparound (e.g. from DSR) locally at the DCE end of
  289.      the cable.
  290.  
  291.      5 CTS Clear To Send
  292.  
  293.      This circuit is the signal that indicates that the DCE is ready
  294.      to accept data from the DTE. In normal operation,  the CTS line
  295.      will be in the  OFF state.  When the  DTE asserts RTS,  the DCE
  296.      will do whatever is necessary to allow data to be sent (e.g.  a
  297.      modem would raise carrier,  and  wait until it stabilized).  At
  298.      this time,  the DCE would set CTS to the ON state,  which would
  299.      then allow the  DTE to  send data.  When  the RTS  from the DTE
  300.      returns to the OFF state,  the DCE releases the channel (e.g. a
  301.      modem would drop carrier),  and  then set  CTS back  to the OFF
  302.      state. Note that a typical DTE must have an incoming CTS before
  303.      it can transmit.  This signal must  either be brought over from
  304.      the DCE, or provided by a wraparound (e.g. from DTR) locally at
  305.      the DTE end of the cable.
  306.  
  307.      6 DSR Data Set Ready
  308.  
  309.      This circuit is the signal that informs the DTE that the DCE is
  310.      alive and well.  It is normally set  to the ON state by the DCE
  311.      upon power-up and left there. Note that a typical DTE must have
  312.      an incoming DSR in order  to function normally.  This line must
  313.      either  be  brought  over  from  the  DCE,  or  provided  by  a
  314.      wraparound (e.g. from DTR) locally at the DTE end of the cable.
  315.      On the DCE end of the  interface,  this signal is almost always
  316.      present,  and may be wrapped back around (to DTR and/or RTS) to
  317.      satisfy required signals whose normal function is not required.
  318.  
  319.      7 SG Signal Ground
  320.  
  321.      This circuit is  the  ground  to  which  all other voltages are
  322.      relative. It must be present in any RS-232 interface.
  323.  
  324.      8 DCD Data Carrier Detect
  325.  
  326.      This circuit is the signal whereby the DCE informs the DTE that
  327.      it has an incoming carrier. It may be used by the DTE to deter-
  328.      mine if the  channel is idle,  so  that the DTE  can request it
  329.      with RTS.  Note that some DTEs must have an incoming DCD before
  330.      they will operate.  In  this case,  this signal  must either be
  331.      brought over from the DCE,  or provided locally by a wraparound
  332.      (e.g. from DTR) locally at the DTE end of the cable.
  333.  
  334.      15 TC Transmit Clock
  335.  
  336.      This circuit provides the clock  for the transmitter section of
  337.      a synchronous DTE.  It  may or may  not be running  at the same
  338.      rate as the  receiver clock.  This  circuit must  be present on
  339.      synchronous interfaces.
  340.  
  341.      17 RC Receiver Clock
  342.  
  343.      This circuit provides the  clock for the  receiver section of a
  344.      synchronous DTE.  It may of may not be running at the same rate
  345.      as the transmitter clock.  Note that both TC and RC are sourced
  346.      by the  DCE.  This  circuit  must  be  present  on  synchronous
  347.      interfaces.
  348.  
  349.      20 DTR Data Terminal Ready
  350.  
  351.      This circuit provides the signal  that informs the DCE that the
  352.      DTE is alive and well.  It  is normally set to  the ON state by
  353.      the DTE at  power-up and  left there.  Note  that a typical DCE
  354.      must have  an incoming  DTR before  it will  function normally.
  355.      This signal must either be brought  over from the DTE,  or pro-
  356.      vided by a wraparound (e.g. from DSR) locally at the DCE end of
  357.      the cable.  On the  DTE side of  the interface,  this signal is
  358.      almost always present,  and may be wrapped back around to other
  359.      circuits (e.g.  DSR,  CTS and/or DCD) to satisfy required hand-
  360.      shaking signals if their normal function is not required.
  361.  
  362.      Note that in an asynchronous  channel,  both ends provide their
  363.      own internal timing,  which (as  long as they  are within 5% of
  364.      each other) is sufficient for them to agree when the bits occur
  365.      within a single character.  In this case, no timing information
  366.      need be sent over the interface  between the two devices.  In a
  367.      synchronous channel,  however,  both  ends must  agree when the
  368.      bits occur over possibly thousands of characters. In this case,
  369.      both devices must use the same clocks.  Note that the transmit-
  370.      ter and receiver may be  running at different rates.  Note also
  371.      that BOTH clocks are provided by  the DCE.  When one has a syn-
  372.      chronous terminal tied  into a  synchronous port  on a computer
  373.      via two synchronous modems,  for  example,  and the terminal is
  374.      transmitting, the terminal's modem supplies the Transmit Clock,
  375.      which is brought directly out to  the terminal at its end,  and
  376.      encodes the clock  with the  data,  sends it  to the computer's
  377.      modem,  which recovers  the  clock  and  brings  it  out as the
  378.      Receive Clock to the computer.  When  the computer is transmit-
  379.      ting,  the same thing  happens in  the other direction.  Hence,
  380.      whichever modem is transmitting must  supply the clock for that
  381.      direction, but on each end, the DCE device supplies both clocks
  382.      to the DTE device.
  383.  
  384.      All of the above  applies to interfacing a  DTE device to a DCE
  385.      device.  In order to interface two  DTE devices,  it is usually
  386.      sufficient to  provide a  'flipped' cable,  in  which the pairs
  387.      (TD, RD), (RTS,CTS) and (DTR,DSR) have been flipped. Hence, the
  388.      TD of one DTE is connected to the RD of the other DTE, and vica
  389.      versa.  It may be necessary to wrap various of the hand-shaking
  390.      lines back around from  the DTR  on each  end in  order to have
  391.      both ends work.  In  a similar manner,  two  DCE devices can be
  392.      interfaced to each other.
  393.  
  394.      An RS-232 'break-out  box'  is  particularly  useful in solving
  395.      interfacing problems.  This  is  a  device  which  is  inserted
  396.      between the DTE and DCE.  Firstly, it allows you to monitor the
  397.      state of the various hand-shaking lines (light on = signal ON /
  398.      logic 0),  and watch the  serial data flicker  on TD and/or RD.
  399.      Secondly,  it allows you to break the connection on one or more
  400.      of the lines (with dip-switches),  and  make any kind of cross-
  401.      connections and/or wraparounds (with jumper wires). Using this,
  402.      it is fairly easy to determine  which line(s) are not function-
  403.      ing as required,  and quickly build a prototype of a cable that
  404.      will serve to  interface the two  devices.  At this point,  the
  405.      break-out box can be  removed and a real  cable built that per-
  406.      forms the same function.  An example  of this kind of device is
  407.      the International  Data  Sciences,  Inc.  Model  60  'Modem and
  408.      Terminal Interface Pocket Analyzer'  (also called a 'bluebox').
  409.      Care should be  taken with this  type of device  to connect the
  410.      correct end of it to the DTE device, or the lights and switches
  411.      do not correspond to the actual signals.
  412.